package com.sh.data.engine.domain.datadev.offline.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.sh.data.engine.domain.base.model.PageResult;
import com.sh.data.engine.domain.datadev.offline.model.domain.*;
import com.sh.data.engine.domain.datadev.offline.model.param.OfflineDevOperationJobSearchParam;
import com.sh.data.engine.domain.datadev.offline.model.param.OfflineDevTaskHistoryJobParam;
import com.sh.data.engine.domain.datadev.offline.model.param.OfflineDevTaskRunParam;
import com.sh.data.engine.domain.datadev.offline.model.param.OfflineDevTaskScriptParam;
import com.sh.data.engine.repository.dao.datadev.entity.DatadevJobEntity;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Date;
import java.util.List;

public interface DatadevJobService extends IService<DatadevJobEntity> {

    boolean haveRecordByNodeId(Long nodeId);

    DatadevJobEntity findTaskFlowLastRecord(Long nodeId);

    DatadevJobEntity findById(Long id);

    Integer findLastAutoExecutionRecordByNodeId(Long nodeId, Date planTime);

    void insertOne(DatadevJobEntity entity);

    void insertBatch(List<DatadevJobEntity> entityList);

    void updateStatus(Long id, Integer status, boolean setStartTime, boolean setEndTime);

    void updateStatusFinished(Long id, Integer status, boolean setStartTime, boolean setEndTime);

    Long startTaskFlowJob(Long taskFlowNodeId, int execType, Long projectId, String userId);

    Long startTaskJob(OfflineDevTaskRunParam offlineDevTaskRunParam);

    void stopJob(Long jobId, int caseTask);

    void stopAllFlowJob(List<Long> ids);

    void stopAllRunningTaskAllProjectId();

    OfflineDevTaskLogDomain getTaskLog(Long jobId, Integer offset, String rsHasShow);

    OfflineDevOperationSummaryDomain getOfflineDevSummary(
        Long nodeId, Long projectId, Integer execType);

    OfflineDevOperationSummaryDomain getHistorySummary(Long nodeId);

    PageResult<OfflineDevOperationJobDomain> getOfflineDevOperationJobPage(
        OfflineDevOperationJobSearchParam offlineDevOperationJobSearchParam);

    List<OfflineDevOperationJobDomain> getOfflineDevOperationJobList(Long id, Integer nodeType);

    Long startTask(Long id, Integer execType, Long projectId, String userId);

    Long startTaskByNodeId(Long nodeId, Long projectId, String userId, Integer execType);

    OfflineDevOperationTaskflowDetailInfoDomain getOfflineDevTaskFlowDetailDomain(Long jobId);

    Object getNodeDetail(Long nodeId) throws IOException;

    void downloadTaskResult(Long jobId, String result, Long projectId, HttpServletResponse response);

    PageResult<OfflineDevOperationJobDomain> getOfflineDevOperationHistoryJobPage(
        OfflineDevTaskHistoryJobParam offlineDevTaskHistoryJobParam);

    List<OfflineDevTaskFlowStatusDomain> getTaskFlowStatus(Long jobId);

    Long startOfflineApiTask(Long nodeId, int execType, Long projectId, String userId);

    Long startOfflineSyncTask(Long nodeId, int execType, Long projectId, String userId);

    Long runRule(Long nodeId, int execType, Long projectId, String userId);

    void dropRecordsByNodeId(Long id);

    void cleanMonthAgoRecord(Date time);

    OfflineDevOperationTodayFinishedDomain getTodayFinished(Long projectId);

    List<OfflineDevOperationFailedTopDomain> getFailedTaskTop(Long projectId, Integer timeType);

    List<OfflineDevOperationRunningTimeTopDomain> getRunningTimeTop(Long projectId, Date runDate);

    OfflineDevOperationTaskMonitorDomain getTaskMonitorError(Long projectId);

    PageResult<OfflineDevOperationTaskMonitorErrorTaskDomain> getTaskMonitorErrorTask(
        Integer timeCase, Long projectId, Integer pageNum, Integer pageSize);

    Boolean saveParams(
        Long nodeId, List<OfflineDevTaskScriptParam> params, Long projectId, String userId);

    Boolean ignoreDataDevJob(String ids);
}
